// Haxzs Audio Server
// made by omghaxzs
// 2010

#include "window.h"
#include "panel.h"

window::window(int y, int x, int width, int height) {
	// Initialize curses screen
	if(has_colors() == FALSE) {	
		endwin();
		printf("Your terminal does not support color\n");
		return;
	}
	
	signal(SIGWINCH, SIG_IGN);

	// Create a new window
	win = newwin(height, width, y, x);

	wrefresh(win);
}

window::~window() {
	endwin();
}

void window::wborder() {
	box(win, 0, 0);
	wrefresh(win);
}

void window::printMsg(std::string msg) {
	wprintw(win,msg.c_str());
	wrefresh(win);
}

void window::printMsg(int y, int x, std::string msg) {
	mvwprintw(win, y, x, msg.c_str());
	wrefresh(win);
}

void window::centerMsg(int y, int x, int width, std::string msg) {
	int length = 0;
	float temp = 0;

	temp = width / 2;
	temp -= msg.length() / 2;

	x+=(int)temp;

	mvwprintw(win, y, x, msg.c_str());
	wrefresh(win);
}

void window::color(int col) {
	wattron(win,COLOR_PAIR(col) | A_BOLD);
}

void window::clrcolor(int col) {
	wattroff(win,COLOR_PAIR(col) | A_BOLD);
}

void window::cursor(int y, int x) {
	wmove(win, y, x);
}

void window::setup() {
	
	// Create a curses window
	initscr();
	curs_set(0);
	start_color();

	// Logo Color
	init_pair(1, COLOR_GREEN, COLOR_BLACK);

	// Waiting color
	init_pair(2, COLOR_YELLOW, COLOR_BLACK);

	// Error Color
	init_pair(3, COLOR_RED, COLOR_BLACK);
}

void window::scrollwnd(bool enabled) {
	scrollok(win, enabled);
}
